package com.jinyi.wwdeng.ui.wallpaper.model

import com.jinyi.base.mvp.BaseModel
import com.jinyi.lib_http.OkGo
import com.jinyi.lib_http.cache.CacheMode
import com.jinyi.lib_http.callback.StringCallback
import com.jinyi.lib_http.model.Response
import com.jinyi.wwdeng.ui.wallpaper.contract.WallPaperContract
import com.jinyi.wwdeng.ui.wallpaper.interfaces.WallPaperLoadDataCallback

/**
 * JinYiTest
 *
 * @Author：wwdeng
 * @CreateTime：2024/4/14 18:42
 * <pre>
 * Model层
</pre> *
 */
class WallpaperModel(iCallBack: WallPaperLoadDataCallback) : BaseModel<WallPaperLoadDataCallback>(iCallBack), WallPaperContract.Model {


    override fun executeGetRequest(url: String) {
        OkGo.get<String>(url) // 请求方式和请求url
            .tag(this) // 请求的 tag, 主要用于取消对应的请求
            .cacheKey("cacheKey") // 设置当前请求的缓存key,建议每个不同功能的请求设置一个
            .cacheMode(CacheMode.NO_CACHE) // 缓存模式，详细请看缓存介绍
            //  .cacheTime(3000)//缓存时间
            .execute(object : StringCallback() {
                override fun onSuccess(response: Response<String>) {
                    if(isCallBackDestory){
                        return
                    }
                    callBack.onSuccess(response.body())
                }

                override fun onError(response: Response<String>) {
                    super.onError(response)
                    if(isCallBackDestory){
                        return
                    }
                    callBack.onFailure(response.body())
                }
            })
    }

    override fun executePostRequest(url: String, params: Map<*, *>?) {}
}
